package Windows.UserInfoWindow;

import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class ResTreeModel implements TreeModel, TreeExpansionListener {
	private JTree tree;
	private TreeNode root;

	public ResTreeModel(JTree tree, TreeNode root) {
		super();
		this.root = root;
		this.tree = tree;
		tree.setModel(this);
		tree.addTreeExpansionListener(this);
	}

	@Override
	public void addTreeModelListener(TreeModelListener arg0) {
		// TODO Auto-generated method stub
//		System.out.println("树-添加监听器"+arg0);
	}

	@Override
	public Object getChild(Object parent, int index) {

		return ((TreeNode) parent).getChildAt(index);
	}

	@Override
	public int getChildCount(Object tn) {

		return ((TreeNode) tn).getChildCount();
	}

	@Override
	public int getIndexOfChild(Object parent, Object child) {

		return ((TreeNode) parent).getIndex((TreeNode) child);
	}

	@Override
	public Object getRoot() {

		return root;
	}

	@Override
	public boolean isLeaf(Object nd) {

		return ((TreeNode) nd).isLeaf();
	}

	@Override
	public void removeTreeModelListener(TreeModelListener arg0) {
//		System.out.println("树-删除监听器："+arg0);
	}

	@Override
	public void treeCollapsed(TreeExpansionEvent te) {
		// TODO Auto-generated method stub
//		System.out.println("树-折叠："+te);
//		tree.treeDidChange();

	}

	@Override
	public void treeExpanded(TreeExpansionEvent te) {
		// TODO Auto-generated method stub
//		System.out.println("树-展开："+te);
//		tree.treeDidChange();
	}

	@Override
	public void valueForPathChanged(TreePath arg0, Object arg1) {
//		System.out.println("树-节点值改变："+arg0+" >> "+arg1);
	}

}
